<template>
  <div class="panel">
    <div class="heading">
      <h2>项目列表</h2>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item><a href="#/app">后台首页</a></el-breadcrumb-item>
        <el-breadcrumb-item
          ><a href="#/app/project">项目管理</a></el-breadcrumb-item
        >
        <el-breadcrumb-item>项目列表</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="search">
      <div class="options">
        <span>客户姓名：</span>
        <el-input
          v-model.trim="keyword2"
          placeholder="请输入内容"
          size="small"
          clearable
        />
        <span>小区名称：</span>
        <el-input
          v-model.trim="keyword3"
          placeholder="请输入内容"
          size="small"
          clearable
          style="margin-right: 0"
        />
      </div>
      <el-button
        type="primary"
        icon="el-icon-plus"
        size="small"
        @click="addItem"
        >创建</el-button
      >
    </div>

    <div class="list">
      <el-table
        :data="pageData"
        border
        style="width: 100%"
        ref="table"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          prop="number"
          type="index"
          label="序号"
          width="50"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="门店名称"
          width="220"
        >
          <template slot-scope="scope">
            <el-popover trigger="click" placement="top">
              <p>门店代码: {{ scope.row.dwdm }}</p>
              <p>门店名称: {{ scope.row.agent_name }}</p>
              <div slot="reference" class="name-wrapper">
                <el-button type="text">{{ scope.row.agent_name }}</el-button>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column
          prop="ow_name"
          label="客户姓名"
          width="100"
          :show-overflow-tooltip="true"
        >
         </el-table-column>
        <el-table-column
          prop="village"
          label="小区名称"
          width="140"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column prop="floor" label="楼层" width="100">
        </el-table-column>
        <el-table-column
          prop="address"
          label="地址"
          width="350"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column prop="phone" label="联系电话" width="130">
        </el-table-column>
        <el-table-column prop="c_price" label="设计费用(元)" width="120">
        </el-table-column>
        <el-table-column prop="status" label="项目状态" width="80">
        </el-table-column>
        <el-table-column
          prop="create_user"
          label="创建用户名称"
          :show-overflow-tooltip="true"
          width="120"
        >
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="创建时间"
          :show-overflow-tooltip="true"
          width="120"
        >
        </el-table-column>

        <el-table-column label="操作" align="center" width="195" fixed="right">
          <template slot-scope="scope">
            <el-button
              @click="editItem(scope.row)"
              type="text"
              icon="el-icon-edit"
              size="small"
              >编辑</el-button
            >
            <el-button
              type="text"
              size="small"
              icon="el-icon-setting"
              @click="seePlan(scope.row)"
              >设计方案</el-button
            >
            <el-button
              type="text"
              size="small"
              icon="el-icon-delete"
              @click="delItem(scope.row.id)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        background
        layout="prev, pager, next"
        :current-page.sync="page"
        :page-size="perpage"
        :total="searchData.length"
        class="el-pagination"
      />
    </div>

    <!-- 新增项目窗口 -->
    <el-dialog
      :title="(form.id ? '修改' : '新增') + '项目'"
      :visible.sync="dialogVisible"
      width="600px"
      top="10vh"
      :close-on-click-modal="false"
    >
      <el-form ref="form" :rules="rules" :model="form" label-width="100px">
        <el-form-item label="客户姓名" prop="ow_name">
          <el-input v-model.trim="form.ow_name" />
        </el-form-item>

        <el-form-item label="小区名称" prop="village">
          <el-input v-model.trim="form.village" />
        </el-form-item>

        <el-form-item label="楼层" prop="floor">
          <el-input v-model.trim="form.floor">
            <i slot="suffix" style="font-style:normal;margin-right: 10px;">楼</i>
          </el-input>
        </el-form-item>

        <el-form-item label="地址" prop="address">
          <el-input
            type="textarea"
            placeholder="请输入内容"
            v-model.trim="form.address"
            maxlength="30"
            show-word-limit
          >
          </el-input>
        </el-form-item>

        <el-form-item label="联系电话" prop="phone">
          <el-input v-model.trim="form.phone" />
        </el-form-item>

        <el-form-item label="设计费用" prop="c_price">
          <el-input v-model.trim="form.c_price">
          <i slot="suffix" style="font-style:normal;margin-right: 10px;">元</i>
          </el-input>
        </el-form-item>

        <el-form-item label="项目状态" prop="status">
          <el-select v-model="form.status" clearable placeholder="请选择" style="width:100%">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="门店名称" prop="dwdm">
          <el-select v-model="form.dwdm" filterable clearable placeholder="请选择（可搜索）" style="width:100%">
            <el-option
              v-for="item in agentList"
              :key="item.agent_code"
              :label="item.agent_name"
              :value="item.agent_code"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 新增方案列表窗口 -->
    <el-dialog
      :title="(form.id ? '修改' : '新增') + '方案'"
      :visible.sync="dialogVisible12"
      width="400px"
      :close-on-click-modal="false"
    >
      <el-form ref="form2" :model="form2" label-width="100px">
        <el-form-item label="方案名称" prop="plan_name">
          <el-input v-model.trim="form2.plan_name" />
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible12 = false">取 消</el-button>
        <el-button type="primary" @click="save2">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 新增原料列表窗口 -->
    <el-dialog
      title="新增材料"
      :visible.sync="dialogVisible8"
      :close-on-click-modal="false"
      width="80%"
      top="10vh"
    >
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="型号或名称：">
          <el-input
            v-model.trim="formInline.PRODUCT_NAME"
            placeholder=""
            style="width: 120px"
          ></el-input>
        </el-form-item>
        <el-form-item label="规格：">
          <el-input
            v-model.trim="formInline.PRODUCT_SIZE"
            placeholder=""
            style="width: 120px"
          ></el-input>
        </el-form-item>
        <el-form-item label="类型：">
          <el-select v-model="formInline.SERIES_CODE" style="width: 120px">
            <el-option label="全部" value=""></el-option>
            <el-option
              :label="item.series_name"
              :value="item.series_code"
              v-for="(item, index) in lx_list"
              :key="index"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="系列：">
          <el-select v-model="formInline.XL_CODE" style="width: 120px">
            <el-option label="全部" value=""></el-option>
            <el-option
              :label="item.xl_name"
              :value="item.xl_code"
              v-for="(item, index) in xl_list"
              :key="index"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="
              sendPageRequest();
              getPageTotal();
            "
            >查询</el-button
          >
        </el-form-item>
      </el-form>
      <el-form ref="form3" :model="form3" label-width="100px">
        <el-table
          max-height="370"
          ref="table"
          border
          :data="material_list"
          @selection-change="handleSelectionChange3"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column label="商品编号" prop="id" width="100">
            <template slot-scope="scope">
              <span
                v-bind:class="
                  product_ids.indexOf(scope.row.id) > -1 ? 'is_select' : ''
                "
                >{{ scope.row.id }}</span
              >
            </template>
          </el-table-column>
          <el-table-column label="型号" prop="product_code" width="250">
            <template slot-scope="scope">
              <span
                v-bind:class="
                  product_ids.indexOf(scope.row.id) > -1 ? 'is_select' : ''
                "
                >{{ scope.row.product_code }}</span
              >
            </template>
          </el-table-column>
          <el-table-column label="类型" prop="seriesname">
            <template slot-scope="scope">
              <span
                v-bind:class="
                  product_ids.indexOf(scope.row.id) > -1 ? 'is_select' : ''
                "
                >{{ scope.row.seriesname }}</span
              >
            </template>
          </el-table-column>
          <el-table-column label="品名" prop="product_name" width="250">
            <template slot-scope="scope">
              <span
                v-bind:class="
                  product_ids.indexOf(scope.row.id) > -1 ? 'is_select' : ''
                "
                >{{ scope.row.product_name }}</span
              >
            </template>
          </el-table-column>
          <el-table-column label="规格" prop="product_size" width="180">
            <template slot-scope="scope">
              <span
                v-bind:class="
                  product_ids.indexOf(scope.row.id) > -1 ? 'is_select' : ''
                "
                >{{ scope.row.product_size }}</span
              >
            </template>
          </el-table-column>
          <el-table-column label="单位" prop="product_untl">
            <template slot-scope="scope">
              <span
                v-bind:class="
                  product_ids.indexOf(scope.row.id) > -1 ? 'is_select' : ''
                "
                >{{ scope.row.product_untl }}</span
              >
            </template>
          </el-table-column>
          <el-table-column label="酷家乐编码" prop="kjl_id">
            <template slot-scope="scope">
              <span
                v-bind:class="
                  product_ids.indexOf(scope.row.id) > -1 ? 'is_select' : ''
                "
                >{{ scope.row.kjl_id }}</span
              >
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageUtil.pageNum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pageUtil.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageUtil.total"
        >
        </el-pagination>
      </el-form>

      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button @click="dialogVisible8 = false">取 消</el-button>
        <el-button type="primary" @click="addOtherList">添 加</el-button>
      </div>
    </el-dialog>

    <!-- 修改方案列表窗口 -->
    <!-- 新增项目窗口 -->
    <el-dialog
      :title="(form.id ? '修改' : '新增') + '项目'"
      :visible.sync="dialogVisible13"
      width="600px"
      top="10vh"
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="客户姓名" prop="ow_name">
          <el-input v-model.trim="form.ow_name" />
        </el-form-item>

        <el-form-item label="小区名称" prop="village">
          <el-input v-model.trim="form.village" />
        </el-form-item>

        <el-form-item label="楼层" prop="floor">
          <el-input v-model.trim="form.floor">
            <i slot="suffix" style="font-style:normal;margin-right: 10px;">楼</i>
          </el-input>
        </el-form-item>

        <el-form-item label="地址" prop="address">
          <el-input
            type="textarea"
            placeholder="请输入内容"
            v-model.trim="form.address"
            maxlength="30"
            show-word-limit
          >
          </el-input>

        </el-form-item>

        <el-form-item label="联系电话" prop="phone">
          <el-input v-model.trim="form.phone" />
        </el-form-item>

        <el-form-item label="设计费用" prop="c_price">
          <el-input v-model.trim="form.c_price">
            <i slot="suffix" style="font-style:normal;margin-right: 10px;">元</i>
          </el-input>
        </el-form-item>

        <el-form-item label="项目状态" prop="status">
          <el-select v-model="form.status" clearable placeholder="请选择" style="width:100%">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              prop="status"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="门店名称" prop="dwdm">
          <el-select v-model="form.dwdm" filterable clearable placeholder="请选择（可搜索）" style="width:100%">
            <el-option
              v-for="item in agentList"
              :key="item.agent_code"
              :label="item.agent_name"
              :value="item.agent_code"
              prop="dwdm"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible13 = false">取 消</el-button>
        <el-button type="primary" @click="save3">确 定</el-button>
      </span>
    </el-dialog>

    <!--设计 iframe-->
    <el-dialog
      :visible.sync="dialogVisible2"
      width="100%"
      height="100vh"
      top="0vh"
      :close-on-click-modal="false"
      :before-close="handleDialogClose"
    >
      <iframe
        :src="iframeUrl"
        frameborder="0"
        width="100%"
        style="height: calc(100vh - 100px)"
      ></iframe>
    </el-dialog>
    <!-- seePlan -->
    <el-dialog
      :visible.sync="dialogVisible9"
      width="80%"
      title="方案列表"
      :close-on-click-modal="false"
    >
      <el-button
        type="primary"
        icon="el-icon-plus"
        size="small"
        @click="addPlan"
        style="float: right; margin-bottom: 20px"
        >创建</el-button
      >
      <el-table
        :data="tableData4"
        border
        style="width: 100%"
        class="plan"
        align="center"
      >
        <el-table-column label="下单" width="50" align="center">
          <template slot-scope="scope">
            <span class="status-info" v-if="scope.row.is_ordered!=1"></span>
            <span class="status-success" v-else></span>
          </template>
        </el-table-column>
        <el-table-column prop="number" label="序号" type="index" width="50">
        </el-table-column>
        <el-table-column prop="plan_name" label="方案名称"> </el-table-column>
        <el-table-column prop="desid" label="方案编码" width="160">
        </el-table-column>
        <el-table-column prop="create_time" label="创建时间"> </el-table-column>
        <el-table-column prop="create_user" label="创建用户名称">
        </el-table-column>
        <el-table-column prop="create_uid" label="创建用户ID">
        </el-table-column>
        <el-table-column label="效果图" width="85" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              icon="el-icon-picture-outline"
              @click="effect(scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="原料清单" width="180" align="center">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.is_obtain == 1"
              type="text"
              icon="el-icon-document"
              @click="getDetailed(scope.row)"
              >再次获取</el-button
            >
            <el-button
              v-else
              type="text"
              style="color: #909399"
              icon="el-icon-document"
              @click="getDetailed(scope.row)"
              >获取清单</el-button
            >
            <el-button
              v-if="scope.row.is_obtain == 1"
              type="text"
              icon="el-icon-search"
              @click="detailed(scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>

        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              icon="el-icon-setting"
              @click="iframe(scope.row)"
              >设计</el-button
            >
            <el-button
              type="text"
              size="small"
              icon="el-icon-delete"
              @click="delPlan(scope.row.cid)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- effect 效果图-->
    <el-dialog
      :visible.sync="dialogVisible4"
      width="75%"
      top="10vh"
      :close-on-click-modal="false"
    >
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="渲染图" name="1">
          <div
            class="demo-image__preview"
            style="
              width: 200px;
              margin: 20px;
              float: left;
              padding: 10px;
              border: solid 1px #cccccc;
            "
            v-for="(item, index) in abc_img"
            :key="index"
          >
            <el-image
              style="width: 100%; height: 100%"
              :src="item.img"
              :preview-src-list="srcList"
            >
            </el-image>

            <p
              v-text="item.roomName"
              style="text-align: center; margin-top: 5px"
            ></p>
          </div>
        </el-tab-pane>
        <!-- <el-tab-pane label="施工图纸" name="second">
          <el-carousel indicator-position="none" height="760px" align="center">
            <el-carousel-item
              class="lunbo-box-item"
              v-for="(item, index) in def_img"
              :key="index"
            >
              <img :src="item.src" class="lunbotu" alt="轮播图" />
            </el-carousel-item>
          </el-carousel>
        </el-tab-pane> -->
      </el-tabs>
    </el-dialog>

    <!-- 原料清单   :header-cell-style="{ background: '#66B1FF' }"-->
    <el-dialog
      :visible.sync="dialogVisible3"
      width="95%"
      top="5vh"
      :close-on-click-modal="false"
    >
      <el-button
        type="primary"
        icon="el-icon-plus"
        size="small"
        @click="addMaterial"
        style="margin-bottom: 20px"
        >新增材料</el-button
      >
      <el-tabs type="card" @tab-click="handleClick" v-model="editableTabsValue">
        <el-tab-pane
          :label="item.space_name"
          :name="'' + index"
          v-for="(item, index) in spacedata"
          :key="index"
        >
        </el-tab-pane>
        <el-table
          ref="mTable"
          :data="materialData"
          border
          max-height="450"
          :summary-method="getSummaries"
          show-summary
          style="width: 100%; margin-top: 20px"
          id="out-table"
          :row-style="rowClass"
        >
          <el-table-column label="空间" width="100">
            <template slot-scope="scope">
              <span
                v-bind:class="[
                  scope.row.is_accurate == '1' ? 'is_accurate' : '',
                  scope.row.spec == '暂未匹配' ? 'is_matching' : '',
                ]"
                >{{ scope.row.space_name }}</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="image_path" label="图片" width="90">
            <template slot-scope="scope">
              <el-image style="width: 60px;border-radius:10px;" :src="scope.row.image_path" :onerror="errorImg">
              </el-image>
            </template>
          </el-table-column>
          <el-table-column prop="kjl_id" label="模型编码" width="170">
            <template slot-scope="scope">
              <span
                v-bind:class="[
                  scope.row.is_accurate == '1' ? 'is_accurate' : '',
                  scope.row.spec == '暂未匹配' ? 'is_matching' : '',
                ]"
                >{{ scope.row.kjl_id }}</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="product_id" label="ERP编码">
            <template slot-scope="scope">
              <span
                v-bind:class="[
                  scope.row.is_accurate == '1' ? 'is_accurate' : '',
                  scope.row.spec == '暂未匹配' ? 'is_matching' : '',
                ]"
                >{{ scope.row.product_id }}</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="type" label="型号名称">
            <template slot-scope="scope">
              <span
                v-bind:class="[
                  scope.row.is_accurate == '1' ? 'is_accurate' : '',
                  scope.row.spec == '暂未匹配' ? 'is_matching' : '',
                ]"
                >{{ scope.row.type }}</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="spec" label="规格">
            <template slot-scope="scope">
              <span
                v-bind:class="[
                  scope.row.is_accurate == '1' ? 'is_accurate' : '',
                  scope.row.spec == '暂未匹配' ? 'is_matching' : '',
                ]"
                >{{ scope.row.spec }}</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="unit" label="单位" width="70">
            <template slot-scope="scope">
              <span
                v-bind:class="[
                  scope.row.is_accurate == '1' ? 'is_accurate' : '',
                  scope.row.spec == '暂未匹配' ? 'is_matching' : '',
                ]"
                >{{ scope.row.unit }}</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="num" label="数量" width="125" align="center">
            <template slot-scope="scope">
              <el-input-number
                v-model="scope.row.num"
                size="mini"
                style="width: 100px"
                @change="
                  updateItem(scope.row.num, scope.row.remarks, scope.row.mid)
                "
                :min="0"
                label="数量"
              ></el-input-number
            ></template>
          </el-table-column>
          <el-table-column prop="remarks" label="备注" width="200">
            <template slot-scope="scope">
                <el-input
                  @change="updateItem(scope.row.num, scope.row.remarks, scope.row.mid)"
                  type="textarea"
                  autosize
                  placeholder="备注"
                  v-model="scope.row.remarks">
                </el-input>
              </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button
                v-if="is_ordered"
                type="text"
                size="small"
                icon="el-icon-delete"
                @click="delMaterial(scope.row.mid)"
                >删除</el-button
              >
              <el-button
                v-else
                type="text"
                size="small"
                icon="el-icon-delete"
                disabled
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-tabs>
      <div
        style="
          text-align: center;
          margin-top: 10px;
          display: flex;
          justify-content: center;
        "
        v-show="showButton"
      >
        <download-excel
          class="export-excel-wrapper"
          :data="materialData"
          :fields="json_fields"
          name="原料清单.xls">
          <el-button type="primary" size="small">导出Excel</el-button></download-excel>
        <el-button type="primary" size="small" v-if="is_ordered" @click="purchase" style="margin-left: 15px">下单</el-button>
        <el-button type="info" plain size="small" v-else disabled style="margin-left: 15px">下单</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="请选择下单门店"
      :visible.sync="openAgent"
      width="20%"
      :before-close="handleClose">
          <el-select v-model="selectDWDM" filterable clearable placeholder="请选择（可搜索）">
            <el-option
              v-for="item in agentList"
              :key="item.agent_code"
              :label="item.agent_name"
              :value="item.agent_code"
            >
            </el-option>
          </el-select>
      <span slot="footer" class="dialog-footer">
        <el-button @click="openAgent = false">取 消</el-button>
        <el-button type="primary" @click="updateDWDM()">确 定</el-button>
      </span>
</el-dialog>
  </div>
</template>

<script>
import axios from "axios";
import $ from "jquery";
import "mavon-editor/dist/css/index.css";
import { searchCd } from "../utils";
import { uuid } from "../utils";
export default {
  data() {
    return {
      json_fields: {
        空间: "space_name", //常规字段
        模型编码: "kjl_id", //支持嵌套属性
        ERP编码: "product_id", //支持嵌套属性
        型号名称: "type", //支持嵌套属性
        规格: "spec", //支持嵌套属性
        单位: "unit", //支持嵌套属性
        数量: "num", //支持嵌套属性
        单价: "price", //支持嵌套属性
        金额: "total_price", //支持嵌套属性
        备注: "remarks", //支持嵌套属性
      },
      json_meta: [
        [
          {
            " key ": " charset ",
            " value ": " utf- 8 ",
          },
        ],
      ],
      lx_list: [],
      xl_list: [],
      material_list: [],
      formInline: {
        PRODUCT_NAME: "",
        PRODUCT_SIZE: "",
        Series_Type: "",
        SERIES_CODE: "",
        XL_CODE: "",
      },
      state: "",
      pj_id: "",
      input: "",
      abc_img: [],
      srcList: [],
      currentPage: "",
      pageSize: "",
      def_img: [
        { src: require("../assets/images/room4.png") },
        { src: require("../assets/images/room5.png") },
        { src: require("../assets/images/room6.png") },
      ],
      iframeUrl: "",
      options: [
        {
          value: "待跟进",
          label: "待跟进",
        },
        {
          value: "已完成",
          label: "已完成",
        },
        {
          value: "进行中",
          label: "进行中",
        },
      ],
      value: "",
      activeName: "1",
      tableData: [],
      tableData4: [],
      tableData3: [],
      state: "",
      desid: "",
      pid: "",
      keyword: "",
      keyword2: "",
      keyword3: "",
      price: "",
      page: 1,
      perpage: 8,
      cateOptions: [],
      ids: [],
      dialogVisible: false,
      dialogVisible2: false,
      dialogVisible3: false,
      dialogVisible4: false,
      dialogVisible8: false,
      dialogVisible9: false,
      dialogVisible12: false,
      dialogVisible13: false,
      form: {},
      form2: {},
      form3: {},
      ctrl_data: {},
      yhdm: "",
      dwdm: "",
      xm: "",
      bm: "",
      cid: "",
      spacedata: [],
      materialData: [],
      fullscreenLoading: false,
      editableTabsValue: 0,
      pageUtil: {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      },
      product_ids: [],
      showButton: false,
      agentList:[],
      is_ordered: true,
      openAgent: false,
      selectDWDM: "",
      //表单规则
      rules: {
        ow_name: { required: true, message: "请输入客户名称" },
        village: { required: true, message: "请输入小区名称" },
        floor: { required: true, message: "请输入楼层" },
        address: { required: true, message: "请输入地址" },
        phone: { required: true, message: "请输入联系电话" },
        c_price: { required: true, message: "请输入设计费用" },
        status: { required: true, message: "请选择项目状态" },
        dwdm: { required: true, message: "请选择门店信息" },
      },
      zeroIndex:'',
      errorImg: 'this.src="' + require('../assets/images/error.png') + '"'
    };
  },
  //创建之后
  created() {
    this.yhdm = localStorage.getItem("yhdm");
    this.dwdm = localStorage.getItem("dwdm");
    this.xm = localStorage.getItem("xm");
    this.bm = localStorage.getItem("bm");
    this.$postHttp(
      `api3/mob/query?proname=JJ8012&yhdm=${this.yhdm}`
    ).then((res) => {
      this.bm=res.rows[0].bm;
    })
    this.getList();
  },
  //挂载之后
  mounted() {
    const me = this;
    if (window.postMessage) {
      var callback = function (ev) {
        console ? console.log(ev.data) : alert(ev.data);
        console.log(ev.data);
        var data = JSON.parse(ev.data);
        if (data.action == "kjl_saved" && data.type == "des") {
          console.log(data.desid); //可以获取当前方案ID
          var ccid = localStorage.getItem("cid");
          this.cid = ccid;
          this.desid = data.desid;
          me.$postHttp(
            `/api3/mob/work?proname=INB012&desid=${data.desid}&cid=${this.cid}`
          ).then((res) => {
            console.log(res);
          });
          me.getList2();

          me.tableData.map();
          // window.location.href = "https://www.qq.com"; //监听到退出动作跳转到百度首页
        }
        if (data.action == "kjl_completed" && data.type == "des") {
          console.log("1"); //可以获取当前方案ID
          // window.location.href = "https://www.qq.com"; //监听到退出动作跳转到百度首页
        }
        console.log(data);

        if (
          ev.origin === "http://www.kujiale.com" ||
          ev.origin === "http://yun.kujiale.com" ||
          ev.origin === "https://www.kujiale.com" ||
          ev.origin === "https://yun.kujiale.com"
        ) {
          // handle message in ev ...
          // var data = JSON.parse(ev.data)
        }
      };
      if ("addEventListener" in document) {
        window.addEventListener("message", callback, false);
      } else if ("attachEvent" in document) {
        window.attachEvent("onmessage", callback);
      }
    } else {
      // 如果不支持postMessage， 则使用ie6/7的window共有属性navigator进行hack
      window.navigator.listenKJL = function (msg) {
        alert(msg);
        // var data = JSON.parse(ev.data)
      };
    }
    // 保存酷家乐工具方案
    function saveKjlTool() {
      var tool = document.getElementsByTagName("iframe")[0]; // 可以通过各种方法获取iframe对象
      tool.contentWindow.postMessage("save_kjl", "*");
    }
    // 传入商品清单
    function sendProductList() {
      var tool = document.getElementsByTagName("iframe")[0]; // 可以通过各种方法获取iframe对象
      tool.contentWindow.postMessage(
        {
          type: "third_model_list",
          data: [
            {
              id: "1",
              obsBrandGoodId: "商品id",
              componentReplaceInfo: [],
            },
            {
              id: "2",
              obsBrandGoodId: "商品id",
              componentReplaceInfo: [
                {
                  materialId: "material_xxx",
                  componentId: "obj_xxx",
                  targetImageUrl: "//qhyxpicoss.kujiale.com/texture...",
                },
                {
                  materialId: "material_xxx",
                  componentId: "obj_xxx",
                  targetImageUrl: "//qhyxpicoss.kujiale.com/texture....",
                },
              ],
            },
          ],
        },
        "*"
      );
    }
  },
  computed: {
    searchData() {
      return this.tableData.filter((item) => {
        const cd1 =
          this.keyword !== "" ? searchCd(this.keyword, item.project) : true; // 条件1

        const cd2 =
          this.keyword2 !== "" ? searchCd(this.keyword2, item.ow_name) : true; // 条件2

        const cd3 =
          this.keyword3 !== "" ? searchCd(this.keyword3, item.village) : true; // 条件3
        return cd1 && cd2 && cd3;
      });
    },
    pageData() {
      let start = (this.page - 1) * this.perpage;
      let end = start + this.perpage;
      return this.searchData.slice(start, end);
    },
  },
  methods: {
    
    //单独修改门店
    updateDWDM(){
      this.$postHttp(
        `/api3/mob/work?proname=INB021&id=${this.pj_id}&dwdm=${this.selectDWDM}`
      ).then((res) => {
        this.getList();
        this.openAgent = false;
      });
    },
    //获取门店
    getStore(){
      if(this.bm=='3D设计部'){
        this.$postHttp(`/api3/mob/query?proname=JJ8011`).then(
          (res) => {
            this.agentList = res.rows;
          }
        );
        return;
      }
      this.$postHttp(`/api3/mob/query?proname=JJ8011&AGENT_CODE=${this.dwdm}`).then(
        (res) => {
          this.agentList = res.rows;
        }
      );
    },
    //关闭弹出层
    handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
    //打开loading
    openFullScreen() {
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        return loading;
    },
    //关闭loading
    closeFullScreen(loading){
        loading.close();
    },
    rowClass({row, rowIndex}) { 
      if (this.zeroIndex === rowIndex ) { 
        return { "background-color": "#f9e3e2"}; 
        } 
    },
    //下单
    parseOrder(dwdm){
            this.$postHttp(
              `/api3/mob/query?proname=JJ8006&desid=${this.desid}&pj_id=${this.pj_id}&cid=${this.cid}`
            ).then((res) => {
              var index = res.rows.findIndex(function(item) {
                  return item.num == 0;
              });
              if (index!=-1) {
                this.zeroIndex = index;
                this.$tableScrollMove('mTable',index);
                this.$message.error("材料数量不能为零！");
                this.closeFullScreen(loading);
              } else {
                this.zeroIndex = '';
                this.$confirm('您确定要下单吗?(未匹配的商品将无法下单至艾订货)', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                var loading = this.openFullScreen();
                this.$postHttp(
                  `/api3/mob/work?proname=INB019&cid=${this.cid}&dwdm=${dwdm}&yhdm=${this.yhdm}`
                ).then((res) => {
                  if(res.result=='ok'){
                    this.$postHttp(
                      `/api3/mob/work?proname=INB019&action=update&cid=${this.cid}`
                    ).then((res) => {
                      if(res.result=='ok'){
                        this.$message.success("已下单到艾订货");
                        this.closeFullScreen(loading);
                        this.is_ordered = false;
                        this.$postHttp(`/api3/mob/query?proname=JJ8002&pj_id=${this.pj_id}`).then(
                          (res) => {
                            console.log(res);
                            this.tableData4 = res.rows;
                          }
                        );
                      }
                    })
                  }else{
                    this.$message.error("下单失败！");
                    this.closeFullScreen(loading);
                  }
                })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消下单'
            });          
          });
              }
            });
      },
    //下单校验
    purchase() {
      //如果不是总部，直接下单
      if(this.bm!='3D设计部'){
        this.parseOrder(this.dwdm);
        return;
      }
      this.$postHttp(
        `/api3/mob/query?proname=JJ8003&layui=1&id=${this.pj_id}`
      ).then((res) => {
        if(res.rows.length<1){
          this.getStore()
          this.openAgent=true;
        }else{
          this.parseOrder(res.rows[0].dwdm);
          alert(res.rows[0].dwdm)
        }
      });
    },
    //数量定位
    $tableScrollMove(refName,index=0){
      if(!refName || !this.$refs[refName]) return//不存在表格的ref vm 则返回
      let vmEl = this.$refs[refName].$el
      if(!vmEl) return
      //计算滚动条的位置
      const targetTop = vmEl.querySelectorAll('.el-table__body tr')[index].getBoundingClientRect().top
      const containerTop = vmEl.querySelector('.el-table__body').getBoundingClientRect().top
      const scrollParent = vmEl.querySelector('.el-table__body-wrapper')
      scrollParent.scrollTop = targetTop - containerTop
    },
    handleDialogClose() {
      document.exitFullscreen();
      this.dialogVisible2 = false;
    },
    handleSizeChange(val) {
      this.pageUtil.pageSize = val;
      this.sendPageRequest();
    },
    handleCurrentChange(val) {
      this.pageUtil.pageNum = val;
      this.sendPageRequest();
    },
    getPageTotal() {
      this.$postHttp(
        `/api3/mob/query?proname=JJ8010&layui=1&PRODUCT_NAME=${this.formInline.PRODUCT_NAME}&PRODUCT_SIZE=${this.formInline.PRODUCT_SIZE}&Series_Type=${this.formInline.Series_Type}&SERIES_CODE=${this.formInline.SERIES_CODE}&XL_CODE=${this.formInline.XL_CODE}`
      ).then((res) => {
        this.pageUtil.total = res.rows[0].total - 0;
      });
    },
    sendPageRequest() {
      this.$postHttp(
        `/api3/mob/query?proname=JJ8007&layui=1&pageNum=${
          (this.pageUtil.pageNum - 1) * this.pageUtil.pageSize
        }&pageSize=${this.pageUtil.pageSize}&PRODUCT_NAME=${
          this.formInline.PRODUCT_NAME
        }&PRODUCT_SIZE=${this.formInline.PRODUCT_SIZE}&Series_Type=${
          this.formInline.Series_Type
        }&SERIES_CODE=${this.formInline.SERIES_CODE}&XL_CODE=${
          this.formInline.XL_CODE
        }`
      ).then((res) => {
        this.material_list = res.rows;
      });
    },
    handleSelectionChange3(val) {
      this.product_ids = val.map((item) => {
        return item.id;
      });
    },
    getSummaries(param) {
      console.info(param);
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总价";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        if (!values.every((value) => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[7] += " ";
          sums[9] += " ";
        } else {
        }
        sums[1] = " ";
        sums[2] = " ";
        sums[3] = " ";
        sums[4] = " ";
        sums[5] = " ";
        sums[6] = " ";
        sums[8] = " ";
        sums[9] = " ";
        sums[10] = " ";
      });
      return sums;
    },
    updateItem(num, remarks, mid) {
      this.materialData.find((a) => {
        if (a.mid == mid) {
          a.total_price = a.num * a.price;
          a.total_price = Math.floor(a.total_price * 100) / 100;
        }
        //return a.mid == mid;
      });
      console.log("更新备注&数量", num, remarks, mid);
      this.$postHttp(
        `/api3/mob/work?proname=INB016&mid=${mid}&remarks=${remarks}&num=${num}&cid=${this.cid}`
      ).then((res) => {
        this.getSonList(res.rows[0].space_name);
      });
    },
    handleClick(tab, event) {
      console.log(tab);
      console.log(
        this.editableTabsValue,
        this.editableTabsValue.length - 1,
        this.editableTabsValue == this.editableTabsValue.length - 1
      );
      if (this.editableTabsValue == this.spacedata.length - 1) {
        this.$postHttp(
          `/api3/mob/query?proname=JJ8006&desid=${this.desid}&pj_id=${this.pj_id}&cid=${this.cid}`
        ).then((res) => {
          this.materialData = res.rows;
        });
        this.showButton = true;
      } else {
        this.getSonList(this.spacedata[this.editableTabsValue].space_name);
        this.showButton = false;
      }
    },
    handleSelectionChange(ids) {
      this.ids = ids.map((item) => item.id);
    },

    getList() {
      if(this.bm!='3D设计部'){
        this.$postHttp(
          `/api3/mob/query?proname=JJ8001&dwdm=${this.dwdm}`
        ).then((res) => {
          // console.log(res);
          this.tableData = res.rows;
        });
      }else{
        this.$postHttp(
          `/api3/mob/query?proname=JJ8001&create_uid=${this.yhdm}`
        ).then((res) => {
          // console.log(res);
          this.tableData = res.rows;
        });
      }
    },
    getList2() {
      this.$postHttp(`/api3/mob/query?proname=JJ8002&pj_id=${this.pj_id}`).then(
        (res) => {
          this.tableData4 = res.rows;
        }
      );
    },
    addItem() {
      this.form = {};
      this.dialogVisible = true;
      this.getStore();
    },
    editItem(row) {
      this.form = { ...row };
      this.dialogVisible13 = true;
      this.getStore();
    },
    delItem(id) {
      this.$confirm("您确定要删除此条记录吗？", "提示")
        .then(() => {
          this.$http
            .post(`api3/mob/work?proname=INB013&id=${id}`)
            .then((res) => {
              if (res.result == "ok") {
                this.$message.success("删除成功");
                this.getList(); // 刷新
              } else {
                this.$message.error("删除失败");
              }
            });
        })
        .catch(() => {});
    },
    delPlan(id) {
      this.$confirm("您确定要删除此条记录吗？", "提示")
        .then(() => {
          this.$http
            .post(`api3/mob/work?proname=INB014&cid=${id}`)
            .then((res) => {
              if (res.result == "ok") {
                this.$message.success("删除成功");
                this.getList2(); // 刷新
              } else {
                this.$message.error("删除失败");
              }
            });
        })
        .catch(() => {});
    },
    delMaterial(mid) {
      this.$confirm("您确定要删除此条材料吗？", "提示")
        .then(() => {
          this.$http.post(`api3/mob/work?proname=INB020&mid=${mid}`).then((res) => {
            if (res.result == "ok") {
              this.$message.success("删除成功");
              let newArr = [];
              let oldArr = this.materialData;
              for(var item of oldArr){
                if(item.mid!=mid){
                  newArr.push(item);
                }
              }
            this.materialData=newArr; // 刷新
            } else {
              this.$message.error("删除失败");
            }
          });
        })
        .catch(() => {});
    },
    addPlan() {
      this.form2 = {};
      this.dialogVisible12 = true;
    },
    addMaterial() {
      this.form3 = {};
      this.dialogVisible8 = true;
      this.$postHttp(`/api3/mob/query?proname=JJ8008`).then((res) => {
        console.log("11111111", res);
        this.lx_list = res.rows;
      });
      this.$postHttp(`/api3/mob/query?proname=JJ8009`).then((res) => {
        this.xl_list = res.rows;
      });
      this.sendPageRequest();
      this.getPageTotal();
    },
    addOtherList() {
      this.$postHttp(
        `/api3/mob/work?proname=INB018&ids=${this.product_ids.join(
          ","
        )}&desid=${this.desid}&owner_id=${this.pj_id}&cid=${
          this.cid
        }&space_name=附加清单`
      ).then((res) => {
        this.dialogVisible8 = false;
        this.$message.success("添加成功");
        if (this.spacedata[this.editableTabsValue].space_name === "合计清单") {
          this.$postHttp(
            `/api3/mob/query?proname=JJ8006&desid=${this.desid}&pj_id=${this.pj_id}&cid=${this.cid}`
          ).then((res) => {
            this.materialData = res.rows;
          });
          return;
        }
        this.getSonList(this.spacedata[this.editableTabsValue].space_name);
      });
    },
    effect(val) {
      const me = this;
      console.log((this.desid = val.desid));
      var timestamp = Date.parse(new Date());
      var sign = me.$md5(
        "Y3PEPVhFTjMvQl25fmRMeN48ZZAnaRWB" + "9wkxAM9wQR" + timestamp
      );
      me.$getHttp(
        `/api2/v2/archive/list?appkey=9wkxAM9wQR&design_id=${this.desid}&timestamp=${timestamp}&sign=${sign}`
      ).then((res) => {
        console.log(res);
      });
      me.$getHttp(
        `/api2/v2/renderpic/list?appkey=9wkxAM9wQR&design_id=${this.desid}&start=0&num=10&timestamp=${timestamp}&sign=${sign}`
      ).then((res) => {
        me.dialogVisible4 = true;
        console.log(res);
        console.log("---", (me.abc_img = res.d.result));
        me.abc_img.forEach((item) => {
          console.log(item.img);
          me.srcList.push(item.img);
        });
        if (res.c === "100005") {
          console.log(res);
        } else {
          //打开图片列表
          console.log(res);
        }
      });
    },
    user_reg() {
      var appuid = JSON.parse(localStorage.getItem("userInfo"));
      var timestamp = Date.parse(new Date());
      var sign = this.$md5(
        "Y3PEPVhFTjMvQl25fmRMeN48ZZAnaRWB" +
          "9wkxAM9wQR" +
          appuid.sj +
          timestamp
      );
      this.$postHttp(
        `api2/v2/register?appkey=9wkxAM9wQR&appuid=${appuid.sj}&timestamp=${timestamp}&sign=${sign}`,
        {
          name: "liao",
          type: 0,
        }
      ).then((resReg) => {
        console.log("reg---", resReg);
      });
    },
    getDetailed(val) {
      var loading = this.openFullScreen();
      var appuid = JSON.parse(localStorage.getItem("userInfo"));
      const me = this;
      console.log((this.desid = val.desid));
      var uid = uuid();
      console.log("----uid:", uid);

      var timestamp = Date.parse(new Date());
      var sign = me.$md5(
        "Y3PEPVhFTjMvQl25fmRMeN48ZZAnaRWB" +
          "9wkxAM9wQR" +
          appuid.sj +
          timestamp
      );
      me.$postHttp(
        `/api2/v2/decoration/listing/init?appkey=9wkxAM9wQR&appuid=${appuid.sj}&design_id=${this.desid}&request_id=${uid}&timestamp=${timestamp}&sign=${sign}`,
        { returnAll: true }
      ).then((res) => {
        console.log(res);
        try {
          if (res.d.status == "SUBMITTED") {
            console.log("任务" + res.d.taskId + "提交成功！");
            this.res_listen(res.d.taskId, this.desid, val.pj_id, val.cid,loading);
          }
        } catch (error) {
          this.$message.error('请先设计此方案！')
          this.closeFullScreen(loading);
        }
      });
      console.log(val);
    },
    getSonList(name) {
      const me = this;
      me.$postHttp(
        `api3/mob/query?proname=JJ8005&space_name=${name}&desid=${this.desid}&pj_id=${this.pj_id}&cid=${this.cid}`
      ).then((res) => {
        me.materialData = res.rows;
        if(res.rows[0].is_ordered==1){
          this.is_ordered = false;
        }else{
          this.is_ordered = true;
        }
      });
    },
    detailed(val) {
      this.cid = val.cid;
      this.materialData = [];
      console.log((this.desid = val.desid));
      const me = this;
      me.$postHttp(
        `api3/mob/query?proname=JJ8004&desid=${this.desid}&pj_id=${this.pj_id}&cid=${val.cid}`
      ).then((res) => {
        this.showButton = false;
        this.spacedata = res.rows;
        this.getSonList(res.rows[0].space_name);
        this.editableTabsValue = "0";
        this.spacedata.push({
          space_name: "附加清单",
          space_id: "2",
          desid: "2",
          sid: "2",
        });
        this.spacedata.push({
          space_name: "合计清单",
          space_id: "1",
          desid: "1",
          sid: "1",
        });

        console.log(this.spacedata);
      });

      this.dialogVisible3 = true;
    },

    res_listen(taskId, desid, pj_id, cid,loading) {
      console.log(pj_id);
      var appuid = JSON.parse(localStorage.getItem("userInfo"));
      const me = this;
      let newsItem = [];
      var timestamp = Date.parse(new Date());
      var sign = me.$md5(
        "Y3PEPVhFTjMvQl25fmRMeN48ZZAnaRWB" +
          "9wkxAM9wQR" +
          appuid.sj +
          timestamp
      );
      me.$getHttp(
        `/api2/v2/decoration/listing/poll?appkey=9wkxAM9wQR&task_id=${taskId}&appuid=${appuid.sj}&design_id=${desid}&timestamp=${timestamp}&sign=${sign}`
      ).then((res) => {
        if (res.d.status === "SUCCESS") {
          console.log(res.d.data);
          console.log(res.d.data.rowItems);
          let newItems = [];
          for (let i = 0; i < res.d.data.rowKeys.length; i++) {
            let f = true;
            for (let j = 0; j < newItems.length; j++) {
              if (newItems[j].roomName === res.d.data.rowKeys[i].roomName) {
                console.log(
                  i,
                  newItems[j].roomName,
                  res.d.data.rowKeys[i].roomName
                );
                f = false;
                for (let k = 0; k < res.d.data.rowItems.length; k++) {
                  if (
                    res.d.data.rowItems[k].rowKeyId ===
                    res.d.data.rowKeys[i].rowKeyId
                  ) {
                    let temp_obj = res.d.data.brandGoodInfos.find(
                      (t) => t.brandGoodKey == res.d.data.rowItems[k].brandGoodKey
                    );
                    console.log("临时数据：" + temp_obj);
                    if (temp_obj.length == 0 || temp_obj == null) {
                      console.log("未查询到...");
                    }
                    let new_obj = {
                      ...temp_obj,
                      ...res.d.data.rowItems[k],
                    };
                    newItems[j].rowItems.push(new_obj);
                  }
                }
              }
            }
            if (f) {
              newItems.push({
                roomName: res.d.data.rowKeys[i].roomName,
                // rowKeyId: res.d.data.rowKeys[i].rowKeyId,
                rowItems: [],
              });

              for (let l = 0; l < res.d.data.rowItems.length; l++) {
                if (
                  res.d.data.rowItems[l].rowKeyId ===
                  res.d.data.rowKeys[i].rowKeyId
                ) {
                  let temp_obj = res.d.data.brandGoodInfos.find(
                    (t) => t.brandGoodKey == res.d.data.rowItems[l].brandGoodKey
                  );
                  if (temp_obj.length == 0 || temp_obj == null) {
                    console.log("未查询到...");
                  }
                  let new_obj = {
                    ...temp_obj,
                    ...res.d.data.rowItems[l],
                  };
                  newItems[newItems.length - 1].rowItems.push(
                    //res.d.data.rowItems[l]
                    new_obj
                  );
                }
              }
            }
          }
          console.log(res.d.data.rowKeys);
          console.log("封装好的数据----", newItems);

          // 封装好数据以后调接口传给后端
          axios.post(`/api1/mob/work?proname=KJLListing&desid=${desid}&pj_id=${this.pj_id}&cid=${cid}`,newItems).then(response=>{
              this.$message.success("获取成功");
              this.closeFullScreen(loading);
              this.$postHttp(`/api3/mob/query?proname=JJ8002&pj_id=${this.pj_id}`).then(
                (res) => {
                  console.log(res);
                  this.tableData4 = res.rows;
                }
              );
          }).catch(err=>{
              console.log(err);
          });
          
          me.$postHttp(
            `/api1/mob/work?proname=INB017&desid=${desid}&is_obtain=1&cid=${cid}`
          ).then((res) => {
            console.log(res);
            this.getList2(this.pj_id);
          });
        }
        if (res.d.status === "NOT_EXIST") {
          console.log("任务未提交！");
        }
        if (res.d.status === "PROCESSING") {
          console.log("处理中...！");
          setTimeout(me.res_listen(taskId, desid, pj_id, cid,loading), 5000);
        }
        if (res.d.status === "FAILURE") {
          console.log("清单任务运行失败！");
        }
        if (res.d.status === "ERROR") {
          console.log("系统异常！");
        }
      });
    },
    iframe(rowdata) {
      console.info("llll:" + rowdata.cid);
      var appuid = JSON.parse(localStorage.getItem("userInfo"));
      localStorage.setItem("cid", rowdata.cid);
      console.log(rowdata);
      this.ctrl_data = rowdata;
      // 点击设计调用token接口，如果失败则调用注册接口
      // this.dialogVisible2 = true;   弹出框是否显示判断于token是否存在，流程》先调用token接口，如果不成功则调用注册接口
      var timestamp = Date.parse(new Date());
      let sign = this.$md5(
        "Y3PEPVhFTjMvQl25fmRMeN48ZZAnaRWB" +
          "9wkxAM9wQR" +
          appuid.sj +
          timestamp
      );
      this.$postForm(
        `api2/v2/sso/token?appkey=9wkxAM9wQR&appuid=${appuid.sj}&timestamp=${timestamp}&sign=${sign}&dest=4`
      ).then((res) => {
        console.log("token---", res);

        if (res.c == 0) {
          localStorage.setItem("accesstoken", res.d);
          console.log(rowdata.desid);
          var iframeUrl = `https://www.kujiale.com/v/auth?accesstoken=${res.d}&dest=4`;
          if (
            rowdata.desid != "" &&
            rowdata.desid != null &&
            rowdata.desid != " "
          ) {
            var iframeUrl = `https://www.kujiale.com/v/auth?accesstoken=${res.d}&dest=4&designid=${rowdata.desid}`;
          }

          this.iframeUrl = iframeUrl;
          this.dialogVisible2 = true;
        }
        if (res.c != 0) {
          // appKey：9wkxAM9wQR
          // appSecret：Y3PEPVhFTjMvQl25fmRMeN48ZZAnaRWB
          // 如果不成功就调用注册接口;  //里面的参数都是文档的参数，
          this.$message.error('未绑定酷家乐账号')
          //this.user_reg();
          return;
        }
        document.documentElement.requestFullscreen()
      });
    },
    save() {
      this.$refs.form.validate((valid) => {
        console.log(this.form);
        if (valid) {
          this.$http
            .post(
              `/api3/mob/work?proname=INB010&c_price=${this.form.c_price}&floor=${this.form.floor}&ow_name=${this.form.ow_name}&phone=${this.form.phone}&status=${this.form.status}&village=${this.form.village}&address=${this.form.address}&create_uid=${this.yhdm}&create_user=${this.xm}&dwdm=${this.form.dwdm}`
            )
            .then((res) => {
              console.log(res);
              if (res.result != "fasle") {
                this.$message.success("添加成功");
                this.getList(); // 刷新
                this.dialogVisible = false;
              } else {
                this.$message.error("添加失败");
              }
            });
        }
      });
    },
    save3() {
      this.$refs.form.validate((valid) => {
        console.log(this.form);
        if (valid) {
          this.$http
            .post(
              `/api3/mob/work?proname=INB015&id=${this.form.id}&c_price=${this.form.c_price}&floor=${this.form.floor}&ow_name=${this.form.ow_name}&phone=${this.form.phone}&status=${this.form.status}&village=${this.form.village}&address=${this.form.address}&dwdm=${this.form.dwdm}`
            )
            .then((res) => {
              console.log(res);
              if (res) {
                this.$message.success("修改成功");
                this.getList(); // 刷新
                this.dialogVisible13 = false;
              } else {
                this.$message.error("修改失败");
              }
            });
        }
      });
    },
    save2() {
      this.$refs.form2.validate((valid) => {
        console.log(this.form2);
        this.form2.pj_id = this.pj_id;
        if (valid) {
          this.$http
            .post(
              `/api3/mob/work?proname=INB011&plan_name=${this.form2.plan_name}&pj_id=${this.form2.pj_id}&create_uid=${this.yhdm}&create_user=${this.xm}`
            )
            .then((res) => {
              console.log(res);
              if (this.form2) {
                this.$message.success("添加成功");
                this.getList2(); // 刷新
                this.dialogVisible12 = false;
              } else {
                this.$message.error("添加失败");
              }
            });
        }
      });
    },
    seePlan(row) {
      const me = this;
      this.pj_id = row.id;
      console.log(this.pj_id);
      console.info("pj-ID" + this.pj_id);
      this.$postHttp(`/api3/mob/query?proname=JJ8002&pj_id=${me.pj_id}`).then(
        (res) => {
          console.log(res);
          this.tableData4 = res.rows;
        }
      );
      me.dialogVisible9 = true;
    },
  },
};
</script>

<style>
.is_accurate {
  color: #f56c6c;
}
.is_matching {
  color: #e6a23c;
}
.is_select {
  color: #409eff;
}
.size150x100 .el-upload {
  width: 150px;
  height: 100px;
}
.el-input {
  margin-right: 35px;
}
.el-image-viewer__wrapper {
  z-index: 99999999999999 !important;
}
.status-info{
  margin-top: 5px;
  display:inline-block;
  width: 15px;
  height:15px;
  background:#f4f4f5;
  border-radius:50%;
  border:2px solid #909399;
}
.status-success{
  margin-top: 5px;
  display:inline-block;
  width: 15px;
  height:15px;
  background:#f0f9eb;
  border-radius:50%;
  border:2px solid #32d8f5;
}
</style>
